/**
 *
 * Module        : Module Size
 * Authors       : Ben Kwint & Arie van der Veek
 * Date          : November 13th 2011
 * Description   : Uses the Lines of code measurement to determin
 *                 the size of a module in terms of lines of code.
 *
 */
module ModuleSize

import IO;
import Set;
import Relation;
import List;

import lang::java::jdt::Java;
import lang::java::jdt::JDT;

import Regular::CommentLines;
import Regular::EmptyLines;
import Regular::StringUtils;


public int countLinesOfCode(list[str] lines){
  int nrOfLines = size(lines);
  
  for( line <- lines)
  { // substract the empty lines and the single comment lines with no prepending code, only whitespace
    // use this loop instead of the premade function to save looping through
    // the file multiple times
    nrOfLines -= (isEmptyLine(line)) ? 1: 0;
    nrOfLines -= (isSingleCommentLine(line)) ? 1 : 0;
  }
  nrOfLines -= MultiLineComment(lines);
  
  return nrOfLines;
}

public int countLOCForClass(loc classLocation){
	list[str] lines = readCodeBlockFromFile(classLocation);
	int nrOfLines = countLinesOfCode(lines);
	return nrOfLines;
}
public list[str] readCodeBlockFromFile(loc fileLocation){
			str testFromFile = readFile(fileLocation);
			return splitStringInLines(testFromFile);
}